#include "lightSource.h"

void LightSource::setUp()
{
//    LightSource::lightSources = new LightSource[NUMBER_OF_LIGHT_SOURCES];

//    glLightModelf(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);

//	Point p0(5,2,-4), p1(25,2,-4);
//	Point l0(1,1,1), l1(1,1,1);

//	LightSource defaultLight(p0,l0,GL_LIGHT0,LightSource::DIRECTED_LIGHT);
//    LightSource otherLight(p1,l1,GL_LIGHT1,LightSource::DIRECTED_LIGHT);

//	LightSource::lightSources[LightSource::DEFAULT_LIGHT_SOURCE] = defaultLight;
//	LightSource::lightSources[LightSource::OTHER_LIGHT] = otherLight;

}

void LightSource::tearDown()
{
//    delete[] LightSource::lightSources;
}

LightSource::LightSource(Point &c, Point newColor, int newId, int newType) : Object(c)
{

    if (validLightSource())
    {
	    color = newColor;
	    id = newId;
	    type = newType;

        glEnable(id); //enables our light source

	}
	else
	{
	    //WARNING("Initializing invalid light source with id %d .\n",newId);
	}
}

void LightSource::draw()
{

    glPushMatrix();

    transformationMatrix();
    glColor3f(V3(getColor()));

    GLfloat lightColor[] = { V3(getColor()), getType() };
    GLfloat lightPos[] = { V3(getCenter()) , getType() };

    glLightfv(getId(), GL_POSITION, lightPos); //setting position
    glLightfv(getId(), GL_DIFFUSE, lightColor); //setting type
    glLightfv(getId(), GL_SPECULAR, lightColor);

    //glutSolidSphere(0.15,15,15);

    glPopMatrix();

}

void LightSource::ambientLight(Point color)
{
    //FIXME maybe I screwed this, cus the vector had a fourth element
    GLfloat ambient_light[] = { V3(color) , 1.0};
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambient_light);
}

bool LightSource::validLightSource()
{
    return true;
}

